import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** 模具维修申请信息 */
export interface RepairAccount {
  id: number // 主键
  code?: string // 单号
  name?: string // 名称
  accountId?: number // 模具台账ID
  faultId?: number // 故障分类Id
  applicantId?: number // 申请人ID
  departId?: number // 申请部门
  urgencyLevel?: number // 紧急程度
  faultTime?: string | Dayjs // 故障时间
  applicationTime?: string | Dayjs // 申请时间
  faultDescription: string // 故障描述
  repairMethod?: number // 维修方式
  status: number // 状态
}

// 模具维修申请 API
export const RepairAccountApi = {
  // 查询模具维修申请分页
  getRepairAccountPage: async (params: any) => {
    return await request.get({ url: `/mold/repair-account/page`, params })
  },

  // 查询模具维修申请详情
  getRepairAccount: async (id: number) => {
    return await request.get({ url: `/mold/repair-account/get?id=` + id })
  },

  // 新增模具维修申请
  createRepairAccount: async (data: RepairAccount) => {
    return await request.post({ url: `/mold/repair-account/create`, data })
  },

  // 修改模具维修申请
  updateRepairAccount: async (data: RepairAccount) => {
    return await request.put({ url: `/mold/repair-account/update`, data })
  },

  // 删除模具维修申请
  deleteRepairAccount: async (id: number) => {
    return await request.delete({ url: `/mold/repair-account/delete?id=` + id })
  },

  /** 批量删除模具维修申请 */
  deleteRepairAccountList: async (ids: number[]) => {
    return await request.delete({ url: `/mold/repair-account/delete-list?ids=${ids.join(',')}` })
  },

  // 导出模具维修申请 Excel
  exportRepairAccount: async (params) => {
    return await request.download({ url: `/mold/repair-account/export-excel`, params })
  },

  // 派工接口
  dispatchRepairAccount: async (id: number, assigneerId: number) => {
    return await request.put({
      url: `/mold/repair-account/dispatch`,
      data: { id, assigneerId }
    })
  },

  // 撤销接口
  cancelDispatchRepairAccount: async (id: number) => {
    return await request.put({ url: `/mold/repair-account/cancel-dispatch?id=${id}` })
  },

  // 审核接口
  auditRepairAccount: async (data: any) => {
    return await request.put({
      url: `/mold/repair-account/audit`,
      data
    })
  }
}
